
$(function(){
    var userCode=$("#userCode");

    userCode.bind("blur",function () {
        var p = makevar(['userCode']);
        if ($('#userCode').val() == '') {
            $('#userCode').next('.m2-regist-errMsg').html('用户名不能为空!');
            $("#zhuce").hide();
            return false;
        }
        else {
            if (!isLegal($('#userCode').val())) {
                $('#userCode').next('.m2-regist-errMsg').html('您输入了非法字符!');
                return false;
            }
            if ($('#userCode').val().length < 6) {
                $('#userCode').next('.m2-regist-errMsg').html('用户名少于6个字符!');
                return false;
            }
            if ($('#userCode').val().length > 15) {
                $('#userCode').next('.m2-regist-errMsg').html('用户名超过15个字符!');
                return false;
            }
            var reg = /^([a-z]|[A-Z])([0-9]|[a-z]|[A-Z]|_){5,14}$/;
            if (!reg.test($('#userCode').val())) {
                $('#userCode').next('.m2-regist-errMsg').html('用户名格式错误');
                return false;
            }
            $('#userCode').next('.m2-regist-errMsg').html('');
        }
        postData("/Home-Register-ckuser_new", p, function (d) {
            if (d.message != ' ') {
                $('#userCode').next('.m2-regist-errMsg').html(d.message);
                if (d.verify_nums > 3) {
                    $('.verify_code_tr').css('display', '');
                }
            } else {
                $('#userCode').next('.m2-regist-errMsg').html('');
            }


        });
        $.ajax({
            url: "/user/userCodeExists",
            type: "GET",
            data: {"userCode": userCode.val()},
            dataType: "json",
            success: function (data) {
                console.log(data);
                if (null == data || null == data.retCode) {
                    alert("用户名重复校验失败！");
                    return;
                }
                if ('F' == data.retCode) {
                    $(".m2-regist-errMsg").css({"color": "red"}).html("该用户名已经被占用");
                    $("#zhuce").hide();
                } else if ('T' == data.retCode) {
                    $(".m2-regist-errMsg").css({"color": "green"}).html("该用户名可以使用");
                    $("#zhuce").show();
                }
            },
            error: function (e) {
                console.log(e);
            }

        });
    });
   
    })

        
